<?php
/**
 * User: dxk <1024114660@qq.com>
 * Date: 2021-04-21
 */
namespace App\Library\Service\SMS;

use App\Library\Service\AliCloud\SMS;

class AliYun
{
    public function sendSMS(string $mobile, string $tpl_code, array $prams, string $sign = ''): array
    {
        $option = [
            'PhoneNumbers' => $mobile,
            'SignName' => $sign ?: config('sys.aliyun.sms_sign'),
            'TemplateCode' => $tpl_code,
            'TemplateParam' => json_encode($prams, JSON_UNESCAPED_UNICODE),
        ];
        $res = (new SMS())->SendSms($option);
        if ($res['code'] !== 0) {
            return $res;
        }
        if ($res['data']['Code'] != 'OK') {
            $res['code'] = 1;
            $res['msg'] = $res['data']['Message'];
        }
        $res['data']['word_count'] = 1;
        return $res;
    }
}
